
#include "gmatlab.h"

// gboolean g_clsoure_matlab_isinvalid(GClosure *);
void mexFunction(int nlhs, mxArray *lhs[], int nrhs, const mxArray *rhs[])
{
  GClosure *closure;
  gboolean ret;
  
  // Check and convert arguments
  if (nrhs != 1) g_matlab_error("gmatlab:numArg", "g_closure_matlab_isinvalid() takes 1 argument");
  if (nlhs != 1) g_matlab_error("gmatlab:numRet", "g_closure_matlab_isinvalid() has 1 return value");
  if (mxGetClassID(rhs[0]) != MX_GPOINTER) g_matlab_error("gmatlab:badType", "g_closure_matlab_isinvalid: Argument must be int, not %s", mxGetClassName(rhs[0]));
  closure = ((gpointer*)mxGetData(rhs[0]))[0];
  
  // Call function
  ret = (closure ? closure->is_invalid : TRUE);
  
  // Prepare return value
  lhs[0] = mxCreateNumericMatrix(1, 1, mxLOGICAL_CLASS, mxREAL);
  ((mxLogical*)mxGetData(lhs[0]))[0] = ret;
}
